import Vue from "vue";
import VueRouter from "vue-router";

import Layout from "@/layout";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    component: Layout,
    meta: {
      title: "首页",
      icon: "yibiaopan"
    },
    redirect: "/dashboard",
    children: [
      {
        path: "/dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "仪表盘" }
      }
    ]
  },
  {
    path: "/order",
    name: "order",
    component: Layout,
    meta: {
      title: "订单管理",
      icon: "dingdan"
    },
    redirect: "/order/list",
    children: [
      {
        path: "/order/list",
        name: "orderList",
        component: () => import("@/views/order/index"),
        meta: {
          title: "订单管理"
        }
      }
    ]
  },
  {
    path: "/account",
    name: "account",
    component: Layout,
    meta: {
      title: "人员管理",
      icon: "renyuan"
    },
    redirect: "/account/list",
    children: [
      {
        path: "/account/list",
        name: "accountList",
        component: () => import("@/views/account/list/index"),
        meta: {
          title: "人员列表"
        }
      },
      {
        path: "/account/apply",
        name: "accountApply",
        component: () => import("@/views/account/apply/index"),
        meta: {
          title: "申请列表"
        }
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    name: "Login",
    hidden: true,
    meta: {
      title: "登录"
    }
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});

// 解决跳转当前路由报错问题
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function(e) {
  return routerPush.call(this, e).catch(err => err);
};

export default router;
